define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pt/job_offer/index' + location.search,
                    add_url: 'pt/job_offer/add',
                    edit_url: 'pt/job_offer/edit',
                    del_url: 'pt/job_offer/del',
                    multi_url: 'pt/job_offer/multi',
                    import_url: 'pt/job_offer/import',
                    table: 'pt_job_offer',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'order.order_no', title: __('订单编号')},
                        {field: 'order.pt_grade', title: __('职称等级')},
                        {field: 'order.user_name', title: __('客户名称')},
                        {field: 'order.agency_serial_no', title: __('总序号')},
                        {field: 'order.district_name', title: __('区域')},
                        {field: 'position_text', title: __('Position')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'offer_status', title: __('Offer_status'),searchList:{ '1':'待处理','2':'已接收','3':'已拒绝'}, formatter:function(v,r,index){ 
                            let status_name = '';
                            switch (v) {
                                case 1:
                                    status_name = '待处理';
                                    break;
                                case 2:
                                    status_name = '已接收';
                                    break;
                                case 3:
                                    status_name = '已拒绝';
                                    break;
                            }
                            return `<span class="label label-primary">${status_name}</span>`;
                        }},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'confirm_time', title: __('Confirm_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'remark', title: __('Remark'), operate:false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.buttons,
                            buttons:[
                                {
                                    name: 'confirm',
                                    text: '确认',
                                    title: '确认',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    extend:' data-area=\'["800px", "800px"]\' data-shade=\'0.3\'',
                                    icon: 'fa fa-edit',
                                    url: 'pt/job_offer/confirm',
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },
        confirm: function () {
            Controller.api.bindevent();
        },
    };
    return Controller;
});
